//新闻信息明细实体
class DataItem{
  String uniquekey; // 访问接口的唯一key
  String title; // 新闻标题
  String date; // 新闻时间
  String category;
  String author_name; // 新闻作者
  String url; // 新闻的url（进入详情页）
  String thumbnail_pic_s; // 新闻封面图
  String thumbnail_pic_s02;
  String thumbnail_pic_s03;

  DataItem(
      this.uniquekey,
      this.title,
      this.date,
      this.category,
      this.author_name,
      this.url,
      this.thumbnail_pic_s,
      this.thumbnail_pic_s02,
      this.thumbnail_pic_s03
      );

  DataItem.map(dynamic obj) {
    this.uniquekey = obj['uniquekey'];
    this.title = obj['title'];
    this.date = obj['date'];
    this.category = obj['category'];
    this.author_name = obj['author_name'];
    this.url = obj['url'];
    this.thumbnail_pic_s = obj['thumbnail_pic_s'];
    this.thumbnail_pic_s02 = obj['thumbnail_pic_s02'];
    this.thumbnail_pic_s03 = obj['thumbnail_pic_s03'];
  }

  String get _uniquekey => uniquekey;
  String get _title => title;
  String get _date => date;
  String get _category => category;
  String get _author_name => author_name;
  String get _url => url;
  String get _thumbnail_pic_s => thumbnail_pic_s;
  String get _thumbnail_pic_s02 => thumbnail_pic_s02;
  String get _thumbnail_pic_s03 => thumbnail_pic_s03;

  Map<String, dynamic> toMap() {
    var map = new Map<String, dynamic>();
    if (uniquekey != null) {
      map['uniquekey'] = uniquekey;
    }
    map['title'] = title ;
    map['date'] = date ;
    map['category'] = category ;
    map['author_name'] = author_name ;
    map['url'] = url ;
    map['thumbnail_pic_s'] = thumbnail_pic_s ;
    map['thumbnail_pic_s02'] = thumbnail_pic_s02 ;
    map['thumbnail_pic_s03'] = thumbnail_pic_s03 ;
    return map;
  }

  DataItem.fromMap(Map<String, dynamic> map) {
    this.uniquekey = map['uniquekey'].toString();
    this.title = map['title'];
    this.date = map['date'];
    this.category = map['category'];
    this.author_name = map['author_name'];
    this.url = map['url'];
    this.thumbnail_pic_s = map['thumbnail_pic_s'];
    this.thumbnail_pic_s02 = map['thumbnail_pic_s02'];
    this.thumbnail_pic_s03 = map['thumbnail_pic_s03'];
  }

}

//新闻信息实体的List（每一页新闻为30条）
class Data{
  List<DataItem> dataItems;
  Data.fromJson(List items){
    dataItems=new List();
    for(var i=0;i<items.length;i++){
      DataItem dataItem=new DataItem(
          items[i]['uniquekey'],
          items[i]['title'],
          items[i]['date'],
          items[i]['category'],
          items[i]['author_name'],
          items[i]['url'],
          items[i]['thumbnail_pic_s'],
          items[i]['thumbnail_pic_s02'],
          items[i]['thumbnail_pic_s03']
      );
      dataItems.add(dataItem);
    }
  }
}

//访问接口后返回的结果实体类
class Result{
  String stat;
  Data data;
  Result(this.stat,this.data);
  Result.fromJson(Map<String,dynamic> jsonStr){
    this.stat=jsonStr['stat'];
    this.data=Data.fromJson(jsonStr['data']);
  }
}
class NewsData{
  String reason;
  Result result;
  int error_code;
  NewsData(this.reason,this.result,this.error_code);
  NewsData.fromJson(Map<String,dynamic> jsonStr){
    this.reason=jsonStr['reason'];
    this.error_code=jsonStr['error_code'];
    this.result=Result.fromJson(jsonStr['result']);
  }
}